from datetime import datetime
from typing import TYPE_CHECKING

from sqlmodel import SQLModel, Field, Relationship

if TYPE_CHECKING:
    from models.image import Image


class Product(SQLModel, table=True):
    id: int = Field(primary_key=True, index=True)
    name: str = Field(max_length=50)
    attribute: int = Field(max_length=16)  # 0:铜门 1：铸铝门 2：智能锁
    price: float = Field(max_length=16)
    image: "Image" = Relationship(back_populates="product")
    created_at: datetime = Field(default_factory=datetime.now)
